@:$ Reference: http://www.dostips.com/DtTipsDateTime.php

@cd /d "D:\_vrDateBAT"

@if exist %cd%\rTime (
@ call:brTime
@exit /b
) ELSE (
@exit /b
)

@:brTime
@set /p vD=< %cd%\vTime
@set /p rD=< %cd%\rTime
@call:jdate vjD %vD:~0,4%/%vD:~4,2%/%vD:~6,2%
@call:jdate rjD %rD:~0,4%/%rD:~4,2%/%rD:~6,2%
@call:jdate njD
@call:jdate2date rjD-vjD+njD YYYY MM DD
@date %YYYY%/%MM%/%DD%
@del %cd%\rTime
@exit /b

@:jdate JD DateStr -- converts a date string to julian day number with respect to regional date format
@:: -- JD [out,opt] - julian days
@:: -- DateStr [in,opt] - date string, e.g. "03/31/2006" or "Fri 03/31/2006" or "31.3.2006"
@:$reference

@http://groups.google.com/group/alt.msdos.batch.nt/browse_frm/thread/a0c34d593e782e94/50ed3430b6446af8#50ed3430b6446af8
@:$created 20060101 :$changed 20080219
@:$source http://www.dostips.com
@SETLOCAL
@set DateStr=%~2&if "%~2"=="" set DateStr=%date%

@set /a yy=%DateStr:~0,4%
@set /a mm=%DateStr:~5,2%
@set /a dd=%DateStr:~8,2%

@set /a JD=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
@ENDLOCAL & IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
@EXIT /b


@:jdate2date JD YYYY MM DD -- converts julian days to gregorian date format
@:: -- JD [in] - julian days
@:: -- YYYY [out] - gregorian year, i.e. 2006
@:: -- MM [out] - gregorian month, i.e. 12 for december
@:: -- DD [out] - gregorian day, i.e. 31
@:$reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html
@:$created 20060101 :$changed 20080219 :$categories DateAndTime
@:$source http://www.dostips.com
@SETLOCAL ENABLEDELAYEDEXPANSION
@set /a L= %~1+68569, N= 4*L/146097, L= L-(146097*N+3)/4, I= 4000*(L+1)/1461001
@set /a L= L-1461*I/4+31, J= 80*L/2447, K= L-2447*J/80, L= J/11
@set /a J= J+2-12*L, I= 100*(N-49)+I+L
@set /a YYYY= I, MM=100+J, DD=100+K
@set MM=%MM:~-2%
@set DD=%DD:~-2%

@(ENDLOCAL & REM RETURN VALUES

@ IF "%~2" NEQ "" (SET %~2=%YYYY%) ELSE echo.%YYYY%
@ IF "%~3" NEQ "" (SET %~3=%MM%) ELSE echo.%MM%
@ IF "%~4" NEQ "" (SET %~4=%DD%) ELSE echo.%DD%
)
@EXIT /bs